package com.twu.biblioteca;

import java.util.ArrayList;

/**
 * Created by mauricio on 10/1/14.
 */
public class Movie extends Checkable {
    private String title;
    private String director;
    private String year;
    private int rating;
    public static ArrayList<Movie> resource = new ArrayList<Movie>();
    private  int id;

    public Movie(String title, String year, String director, int rating) {
        setTitle(title);
        setDirector(director);
        setYear(year);
        setRating(rating);
        this.id = resource.size();
    }
    public Movie() {
        this.id = resource.size();
    }

    public int getId() {
        return this.id;
    }
    public String getTitle() {
        return this.title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public static ArrayList<Movie> getAll() {
        if(resource.size() == 0) {
            resource.add(new Movie("Simple Man", "2002", "Jonas Melo", 10));
            resource.add(new Movie("Another Level", "2016", "Joventina Silva", 5));
        }

        return resource;
    }


    public void setDirector(String director) {
        this.director = director;
    }

    public String getYear() {
        return this.year;
    }

    public void setYear(String year) {
        this.year = year;
    }

    public int getRating() {
        return this.rating;
    }

    public void setRating(int rating) {
        this.rating = rating;
    }

    public String getDirector() {
        return this.director;
    }

    public static boolean isValid(Object obj) {
        int num;
        try {
            num = Integer.parseInt(obj.toString());
        }
        catch(NumberFormatException nfe) {
            return false;
        }

        if ((num < resource.size() && num > 0) || num == 0 ) {
            return true;
        }

        return false;
    }


    public String toString() {
        return "[" + getId() + "] " +  getTitle() + " - " + getYear() + " - " + getDirector() + " - " + getRating();
    }
}
